<template>
  <el-form ref="modifyUserInfoForm" label-width="78" :rules="rule" :model="data">
    <el-form-item label="账号" prop="username" >
      <el-input v-model="data.username" />
    </el-form-item>
    <el-form-item label="昵称" prop="nickname">
      <el-input v-model="data.nickname" />
    </el-form-item>
    <el-form-item label="邮箱" prop="email">
      <el-input v-model="data.email" />
    </el-form-item>
    <el-form-item v-if="isInsert" label="密码" prop="password">
      <el-input v-model="data.password" type="password" show-password/>
    </el-form-item>
    <el-form-item v-if="isInsert" label="确认密码" prop="checkPassword">
      <el-input v-model="data.checkPassword" type="password" show-password/>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'UserBaseForm',
  props: { modelValue: {}, isInsert: { default: false } },
  computed: {
    data: {
      get () {
        return this.modelValue
      },
      set (val) {
        this.$emit('update:modelValue', val)
      }
    }
  },
  setup () {
    return {
      rule: {
        username: [
          { required: true, message: '请输入账号名', trigger: 'blur' }
        ],
        nickname: [
          { required: true, message: '请输入昵称', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        checkPassword: [
          { required: true, message: '请再次确认密码', trigger: 'blur' }
        ]
      }
    }
  }
}
</script>

<style scoped>

</style>
